# -*- coding: UTF-8 -*-
# __author__ = '10459'







def fun1(dict1):
    count = 0
    count1=0
    count2=0
    count3=0
    for key, value in dict1.items():
        count2 +=1
        print("======第"+str(count2)+"次循环=====")
        if "." in key:
            count += 1
            print("打印第" + str(count) + "次")
            parts = key.split(".")
            print("${part}:" +str(count))
            print("parts="+str(parts))

            par = dict2
            key = parts.pop(0)
            print("${part}去除后:"+str(count))
            print("parts="+str(parts))
            print("${key}:"+str(count))
            print("key="+str(key))
            print("value="+str(value))
            while parts:
                count3 +=1
                print("》》》》第"+str(count3)+"次小循环》》》》》》")
                count1 +=1
                print("小循环par前"+"key="+key)
                par = par.setdefault(key,{})
                print("小循环par后"+"key="+key)
                print("小循环par="+str(par))
                key = parts.pop(0)
                print("${parts1}去除后:"+str(count1))
                print("parts="+str(parts))
                print("key="+str(key))
            par[key] = value
            print("par="+str(par))
        else:
            dict2[key] = value

dict1 = {"a": 1, "b": 2, "c.1": 3, "c.2": 4, "d.5.2": 5, "d.5.3": 6, "d.4.1": 7}
# 实现效果,dict2={"a": 1, "b": 2, "c":{"1":3,"2":4} ,"d":{"5":{"2":5,"3":6},"4":{"1":7}}}
dict2 = {}

fun1(dict1)
print("dict2="+str(dict2))
